#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
int main()
{
  pid_t pid;
  pid = fork();
  if (pid == 0)
  {
    printf("child process\n");
    while (1)
    {
      sleep(1);
      printf("child pid = %d\n", getpid());
    }

    printf("child process exit\n");
    exit(0);
  }
  else
  {
    printf("parent process\n");
    sleep(3);
    kill(pid, SIGKILL); // kill -9 pid 杀死指定进程,pid = 0时,杀死进程组内所有进程,pid = -1 时,杀死可以杀死的所有进程
    printf("parent process exit\n");
    exit(0);
  }
}
